<template>
  <view class="confirm_page">
    <view class=" _w-max _top _left _z-index-5 _pos-fixed _top _left" style="background-color: #008DFF;">
      <view :style="{ width: '100%', height: recHeight }"></view>
      <view class="felx_c h_96 f_s_18" style="position: relative;height: 96rpx;color: #FFFFFF;">
        <view @click="back" style="position: absolute;left: 24rpx;top: 24rpx;">
          <image style="width: 48rpx;height: 48rpx;"
            src="https://taxi.raxan.xyz/wechat/static/images/store_detail/a-chevron-left.png" mode="" />
        </view>
        订单详情
      </view>
    </view>
    <view style="position: absolute;z-index: 0;left: 0;top: 0;right: 0;">
      <image src="https://taxi.raxan.xyz/wechat/static/images/order_header_20241103.png" style="width: 100%;" mode="" />
    </view>
    <view :style="{ width: '100%', height: recHeight }"></view>
    <view style="height: 96rpx;"></view>
    <view style="position: relative;height: 306rpx;z-index: 1;">
      <view style="position: relative;z-index: 1;margin: 32rpx;">
        <view class="white_blod">{{ getLabel('status') }} </view>
        <view class="white_normal">{{ getLabel('copy_writing') }}</view>
      </view>
    </view>
    <!-- 主体内容 -->
    <view class="container">
      <view class="desc">
        <view class="board">
          <view class="row_1">
            <image class="thumb" :src="getLabel('pic')" />
            <view class="info">
              <view class="name">{{ getLabel('type_name') }}</view>
              <view style="font-weight: bold;font-size: 28rpx;color: #008DFF;">{{getLabel('periods')}}期</view>
              <view style="margin-top: 10rpx;">每期金额： <text
                  style="font-weight: bold;font-size: 28rpx;color: #FF5700;">￥{{getLabel('per_price')}}</text> </view>
              <!-- <view class="params">{{getLabel('seat_num')}}座/{{ getLabel('door') }}门/{{ getLabel('gear') }}</view> -->
            </view>
          </view>
          <view style="border-top: 2rpx solid #E7E7E7;margin-top: 10rpx;">
            <view style="display: flex;align-items: center;margin-top: 24rpx;">
              <view
                style="width: 14rpx;height: 14rpx;background: #047EFB;border-radius: 0rpx 0rpx 0rpx 0rpx;border-radius: 50%;">
              </view>
              <view style="font-weight: bold;font-size: 26rpx;color: #333333;margin-left: 10rpx;">
                用车时间：{{getLabel('due')}}</view>
            </view>
            <view style="display: flex;align-items: center;margin-top: 24rpx;">
              <view
                style="width: 14rpx;height: 14rpx;background: #FF5700;border-radius: 0rpx 0rpx 0rpx 0rpx;border-radius: 50%;">
              </view>
              <view style="font-weight: bold;font-size: 26rpx;color: #333333;margin-left: 10rpx;">
                用车时间：{{getLabel('title')}}</view>
            </view>
          </view>

        </view>
      </view>

      <view class="box">
        <view class="title" style="font-weight: bold;">订单信息</view>
        <view class="row">
          <view class="label">订单编号</view>
          <view class="value">{{ getLabel('order_sn') }}</view>
        </view>
        <view class="row">
          <view class="label">下单时间</view>
          <view class="value">{{ getLabel('create_time') }}</view>
        </view>
        <view class="row">
          <view class="label">费用</view>
          <view class="value">¥{{ getLabel('per_price')}}</view>
        </view>
        <view class="row">
          <view class="label">支付方式</view>
          <view class="value">对公转账</view>
        </view>
      </view>
    </view>
    <template>
      <view class="bottom_bar">
        <view class="cancel_order" @click="handleclcu" v-if="detail.status=='还款中'||detail.status=='已完成'">车辆出租</view>
        <view class="cancel_order" @click="handleviewht">查看合同</view>
        <!-- <template v-if="detail.status_id === 0"> -->
        <view class="to_pay" @click="handlePay" v-if="detail.status=='还款中'">对公还款</view>
        <!-- </template> -->
      </view>
    </template>
  </view>
</template>
<script>
  import {
    orderDetail,
    payOrder
  } from '@/api/car.js';
  export default {
    data() {
      return {
        id: 0,
        recHeight: 0,
        detail: {},
        canecl_reason: '',
        cancel_id: '',
        isLoaded: false,
      }
    },
    onShow() {
      // if (this.id) {
      //   this.orderDetail();
      //   uni.pageScrollTo({
      //     scrollTop: 0,
      //     duration: 300
      //   });
      // }
    },
    onLoad(options) {
      this.id = options.order_id;
      this.getPhoneInfo();
      this.orderDetail();
      setTimeout(() => {
        this.isLoaded = true;
      }, 300)
    },
    methods: {
      // 对公还款
      handlePay() {
        console.log(12312123)
        uni.navigateTo({
          url: '/pages/car_sub/per_period_cost/index?type=1&order_id=' + this.id
        })

      },
      // 车辆出租
      handleclcu() {
        uni.navigateTo({
          url: '/pages/hire_sub/publish/index'
        })
      },
      // 查看合同
      handleviewht() {
        uni.navigateTo({
          url: '/pages/car_sub/look_contract/index?order_id=' + this.id + '&type=1'
        })
      },
      getLabel(field) {
        const val = this.detail[field];
        const isNull = val === undefined || val === null;
        return isNull ? '' : val
      },
      back() {
        uni.navigateBack()
      },
      getPhoneInfo() {
        uni.getSystemInfo({
          success: (res) => {
            this.recHeight = res.statusBarHeight + 'px';
          }
        });
      },
      checkLoading(fn) {
        this.loading = true;
        uni.showLoading({
          title: '加载中'
        })
        fn().finally(() => {
          this.loading = false;
          uni.hideLoading()
        })
      },
      orderDetail() {
        this.checkLoading(
          () => orderDetail({
            id: this.id,
            is_new: 1
          }).then(res => {
            this.detail = res.data;
          })
        )
      },
    }
  }
</script>
<style lang="scss" scoped>
  .f_s_18 {
    font-size: 36rpx;
  }

  .white_blod {
    font-family: PingFang SC, PingFang SC;
    font-weight: 600;
    font-size: 46rpx;
    color: #FFFFFF;
    line-height: 54rpx;
    text-align: left;
    font-style: normal;
    text-transform: none;
    margin-bottom: 20rpx;
  }

  .white_normal {
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    font-size: 26rpx;
    color: #FFFFFF;
    line-height: 30rpx;
    text-align: left;
    font-style: normal;
    text-transform: none;
  }

  .bottom_bar {
    position: fixed;
    z-index: 999;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #FFFFFF;
    padding: 32rpx;
    border-top: 1px solid #E7E7E7;
    box-sizing: border-box;
    height: 160rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 32rpx;

    .cancel_order,
    .to_pay {
      line-height: 96rpx;
      text-align: center;
      font-family: PingFang SC, PingFang SC;
      font-weight: 600;
      font-size: 32rpx;
      border-radius: 12rpx;
    }

    .cancel_order {
      flex: 0 0 220rpx;
      width: 220rpx;
      background-color: #F2F3FF;
      color: #008DFF;
    }

    .to_pay {
      flex: 1;
      color: #FFFFFF;
      background-color: #008DFF;
    }
  }

  .felx_c {
    display: flex;
    align-items: center;
    justify-content: center;
  }



  .confirm_page {
    position: relative;
    z-index: 0;
    box-sizing: border-box;
    padding-bottom: 180rpx;

    .top_bg {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      z-index: 0;
      height: 456rpx;
    }
  }

  .container {
    position: relative;
    z-index: 1;
    padding: 16rpx 32rpx 32rpx 32rpx;
    margin-top: -110rpx;

    .desc {
      margin-bottom: 24rpx;

      .board {
        position: relative;
        z-index: 1;
        margin-top: -22rpx;
        background-color: #FFFFFF;
        border-radius: 16rpx;
        padding: 32rpx;
        padding-top: 44rpx;

        .row_1 {
          display: flex;
          gap: 24rpx;

          .thumb {
            width: 230rpx;
            height: 120rpx;
            flex: 0 0 230rpx;
          }

          .info {
            flex: 1;
            overflow: hidden;

            .name {
              margin: 8rpx 0;
              font-family: PingFang SC, PingFang SC;
              font-weight: 600;
              font-size: 40rpx;
              color: rgba(0, 0, 0, 0.9);
              line-height: 56rpx;
            }

            .params {
              font-family: PingFang SC, PingFang SC;
              font-weight: 400;
              font-size: 24rpx;
              color: rgba(0, 0, 0, 0.6);
              line-height: 40rpx;
            }
          }
        }

        .row_2 {
          display: flex;
          margin-top: 24rpx;
          margin-bottom: 18rpx;
          align-items: center;
          justify-content: flex-start;
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 32rpx;
          color: rgba(0, 0, 0, 0.9);
          height: 48rpx;

          .arrow-right {
            flex: 0 0 36rpx;
            width: 36rpx;
            height: 36rpx;
          }
        }

        .row_3 {
          .time_info {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            gap: 8rpx;

            .tag {
              padding: 0 8rpx;
              border-radius: 4rpx;
              border: 1rpx solid #008DFF;
              line-height: 40rpx;
              font-size: 24rpx;
              color: #008DFF;
            }

            .time {
              font-family: PingFang SC, PingFang SC;
              font-weight: 400;
              font-size: 28rpx;
              color: rgba(0, 0, 0, 0.6);
            }
          }

          .days {
            margin: 8rpx 0;
            line-height: 40rpx;
            padding: 0 10rpx;
            background: #F8F9FC;
            border-radius: 8rpx;
            color: #FF5700;
            font-size: 28rpx;
            display: inline-block;
          }
        }
      }
    }

    .box {
      background-color: #FFFFFF;
      padding: 32rpx;
      border-radius: 16rpx;
      margin-bottom: 20rpx;

      &:last-child {
        margin-bottom: 0;
      }

      .title {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 32rpx;
        color: #000000;
        line-height: 38rpx;
        text-align: left;
        font-style: normal;
        text-transform: none;
        margin-bottom: 28rpx;
      }

      .row {
        overflow: hidden;
        margin-bottom: 28rpx;

        &:last-child {
          margin-bottom: 0;
        }

        .label {
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 28rpx;
          color: rgba(0, 0, 0, 0.6);
          line-height: 33rpx;
          text-align: left;
          font-style: normal;
          text-transform: none;
          float: left;
        }

        .value {
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 28rpx;
          color: rgba(0, 0, 0, 0.9);
          line-height: 33rpx;
          text-align: right;
          font-style: normal;
          text-transform: none;
          float: right;
        }
      }
    }
  }
</style>